package com.mapper;

import com.entity.Department;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.vo.DepartmentVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  部门Mapper 接口
 * </p>
 *
 * @author aiou
 * @since 2025-06-12
 */
@Mapper
public interface DepartmentMapper{

    //查询全部部门
    @Select("select * from department")
    List<Department> list();

    //部门管理
    List<DepartmentVO> listDepartMentVO();

    //部门管理-保存
    @Insert("insert into department(department_name,parent_id,chairman,remark) values(#{departmentName},#{parentId},#{chairman},#{remark})")
    boolean insert(Department department);

    //部门管理-修改
    @Update("update department set department_name = #{departmentName},parent_id = #{parentId},chairman = #{chairman},remark = #{remark} " +
            "where department_id = #{departmentId}")
    boolean updateById(Department department);

    //部门管理-查找部门信息
    @Select("select * from department where department_id = #{id}")
    Department getById(Integer id);

    //部门管理-删除
    @Delete("delete from department where department_id = #{id}")
    boolean deleteById(Integer id);

    //部门管理-判断是否为父部门，父部门不允许删除
    @Select("select * from department where parent_id = #{id}")
    List<Department> selectByParentId(Integer id);
}
